let path = require('path')
let webpack = require('webpack')
let webpackStream = require('webpack-stream')
let nodemonConfig = require('../../config/nodemon.conf')

module.exports = (gulp, $, ispod) => {
    let webpackConfig = require('../../webpack')(ispod, 'web')
    gulp.task('dev:bower', done => {
        let stream = $.nodemon(Object.assign({}, nodemonConfig, {
            script: path.resolve(__dirname, '..', 'devServer.js')
        }))
        stream.on('restart', () => {
            console.log('restarted!')
        }).on('crash', function () {
            console.error('Application has crashed!\n')
            stream.emit('restart', 10)  // restart the server in 10 seconds
        })
    })
    gulp.task('build:bower', () => {
        return gulp.src('src/js/app.js')
            .pipe(webpackStream(webpackConfig, webpack))
            .pipe(gulp.dest('dist/js'))
    })
    gulp.task('ana:bower', () => {
        return gulp.src('src/js/app.js')
            .pipe(webpackStream(webpackConfig, webpack))
            .pipe(gulp.dest('dist/js'))
    })
}
